/**
 * 
 */
package il.ac.bgu.cs.heuristics.graph.pddl.parser;

import il.ac.bgu.cs.heuristics.graph.ActionEdge;
import il.ac.bgu.cs.heuristics.graph.Path;
import il.ac.bgu.cs.heuristics.graph.State;
import il.ac.bgu.cs.heuristics.graph.Substitution;
import il.ac.bgu.cs.heuristics.graph.pddl.auxiliary.ContradictionResolver;
import il.ac.bgu.cs.heuristics.graph.pddl.parser.types.ITypedConstant;
import il.ac.bgu.cs.heuristics.graph.pddl.parser.types.Predicate;
import il.ac.bgu.cs.heuristics.graph.types.IState;
import il.ac.bgu.cs.heuristics.graph.types.ISubstitution;
import il.ac.bgu.cs.heuristics.utils.CollectionUtils;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author haro
 * 
 */
public class TestUtils {

	public static final String			CONTRADICTIONS_FILE_NAME	= "contradictions.txt";
	public static final String			NO_CONTRADICTIONS_FILE_NAME	= "no_contradictions.txt";
	public static final Predicate		AT_PREDICATE				= ExpressionParser
																			.parsePredicate("(at ?x - person ?y - location)");

	public static final Predicate		PRESENT_PREDICATE			= ExpressionParser
																			.parsePredicate("(present ?x - person ?y - location)");

	public static final Predicate		ON_PLANE_PREDICATE			= ExpressionParser
																			.parsePredicate("(on-plane ?X1 - object)");

	public static final Predicate		NOT_ON_VACATION_PREDICATE	= ExpressionParser
																			.parsePredicate("(not (on-vacation ?X1 - object))");

	public static final Predicate		ON_VACATION_PREDICATE		= ExpressionParser
																			.parsePredicate("(on-vacation ?X1 - object)");

	public static final Predicate		IS_TRUE						= ExpressionParser
																			.parsePredicate("(is ?X1 - object)");

	public static final Predicate		IS_FALSE					= ExpressionParser
																			.parsePredicate("(not (is ?X1 - object))");

	public static final ITypedConstant	X1							= (ITypedConstant) ExpressionParser
																			.parseTypedParameter("x1 - var");

	public static final ITypedConstant	X2							= (ITypedConstant) ExpressionParser
																			.parseTypedParameter("x2 - var");

	public static final ITypedConstant	X3							= (ITypedConstant) ExpressionParser
																			.parseTypedParameter("x3 - var");

	public static ITypedConstant[]		VAR_ARRAY_3					= { X1, X2,
			X3														};

	public static ITypedConstant[]		VAR_ARRAY_2					= { X1, X2 };

	public static ITypedConstant[]		VAR_ARRAY_1					= { X1 };
	public static ITypedConstant[]		VAR_ARRAY_1_X3				= { X3 };

	public static final ITypedConstant	PERSON_A					= (ITypedConstant) ExpressionParser
																			.parseTypedParameter("bobo - person");

	public static final ITypedConstant	PERSON_B					= (ITypedConstant) ExpressionParser
																			.parseTypedParameter("coco - person");

	public static final ITypedConstant	LOCATION_A					= (ITypedConstant) ExpressionParser
																			.parseTypedParameter("room1 - location");

	public static final ITypedConstant	LOCATION_B					= (ITypedConstant) ExpressionParser
																			.parseTypedParameter("room2 - location");

	public static ISubstitution createSubstitution(
			ContradictionResolver resolver, Predicate p,
			ITypedConstant... constants) {
		final Substitution.Builder builder = new Substitution.Builder(p,
				resolver);
		for (ITypedConstant constant : constants) {
			builder.addConstant(constant);
		}
		return builder.build();
	}

	public static IState createState(ISubstitution... subs) {
		Set<ISubstitution> set = new HashSet<ISubstitution>();
		for (ISubstitution sub : subs) {
			set.add(sub);
		}
		return State.createState(set);
	}

	public static Path createPath(ActionEdge... actions) {
		List<ActionEdge> edges = CollectionUtils.newArrayList();
		for (ActionEdge sub : actions) {
			edges.add(sub);
		}
		Path path = new Path(edges);
		return path;
	}

}
